with recursive fromstopsrecur (source, stop_id, parent_station) as (
  select
    source,
    stop_id,
    coalesce(parent_station, stop_id)
  from stops
  union
  select
    stops.source,
    stops.stop_id,
    coalesce(stops.parent_station, stops.stop_id)
  from stops
  inner join fromstopsrecur
    on
    fromstopsrecur.source = stops.source and
    (fromstopsrecur.stop_id = stops.parent_station or stops.stop_id = fromstopsrecur.parent_station)
)

select * from fromstopsrecur
